﻿using wx_api.CSM.Common;
using wx_api.Tools.Password;
using System;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Http;

namespace FileSC.WEBService.Plugins
{
    internal class TestPlug : PluginBase, IHttpPlugin
    {
        public async Task OnHttpRequest(IHttpSessionClient client, HttpContextEventArgs e)
        {
            var request = e.Context.Request;//http请求体
            var response = e.Context.Response;//http响应体
            response.Headers.Add(HttpHeaders.Server, HttpCommon.SERVER);
            response.Headers.Add(HttpCommon.AUTH_FW, PassGen.MakePassword(7));

            if (request.IsGet() && request.UrlEquals("/wx-api/say-hi"))
            {
                //直接响应文字
                await response
                        .SetStatus(200, "success")
                        .FromText("Success")
                        .AnswerAsync();//直接回应
                return;
            }
            //无法处理，调用下一个插件
            await e.InvokeNext();
        }
    }
}
